{% if storeConfig.newsbreak_pixel_cfg %}
{% assign newsbreak_pixels = storeConfig.newsbreak_pixel_cfg | strtoarray %}
{% get_pixels_domain list={newsbreak_pixels} pixels_platform=newsbreak %}

{% if list %}
<script type='text/javascript'>
    !(function (e, n, t, i, p, a, s) {
      e[i] ||
        (((p = e[i] = 
          function () {
            p.process ? p.process.apply(p, arguments) : p.queue.push(arguments);
          }).queue = []),
        (p.t = +new Date()),
        ((a = n.createElement(t)).async = 1),
        (a.src = 'https://static.newsbreak.com/business/tracking/nbpixel.js?t=' + 864e5 * Math.ceil(new Date() / 864e5)),
        (s = n.getElementsByTagName(t)[0]).parentNode.insertBefore(a, s));
    })(window, document, 'script', 'nbpix');

    document.addEventListener("DOMContentLoaded",function(){
      var newsbreak_pixels ={{list| json}};
      var pixels = newsbreak_pixels.map(function(item){
        return `ID-${item.facebook_pixel_id}`
      })
      nbpix('init', `ID-${newsbreak_pixels[0].facebook_pixel_id}`)

      nbpix('event', "pageload")

      function pushNewsbreakPixel(){
        nbpix.apply(null,['event',...arguments] );
      }
      window['TOP_GLOBAL_CALLBACK_LAYER'].register({
        view_content:function(){
          pushNewsbreakPixel("view_content",{
            "nb_value":_GET_C_SETTING_('product')?_GET_C_SETTING_('product').variant.price:0
          })
        },
        search:function(){
          pushNewsbreakPixel("search")
        },
        purchase:function(){
          pushNewsbreakPixel("complete_payment", {
            "nb_value":  _GET_C_SETTING_('order')?_GET_C_SETTING_('order').total_price:0 
          })
        },
        page_view:function(){
          pushNewsbreakPixel("page_view")
        },
        add_to_cart:function(ecdata){
          var ids = [];
          ids.push(ecdata['ec_data_spu']);
          pushNewsbreakPixel("add_to_cart",{
            "nb_value":ecdata['ec_data_price'] * ecdata['ec_data_quantity']
          })
        },
        add_payment_information:function(){
          pushNewsbreakPixel("add_payment_info")
        },
        add_to_wishlist:function(){
          pushNewsbreakPixel("add_to_wishlist")
        },
        place_an_order:function(){
          pushNewsbreakPixel("place_an_order")
        },
        begin_checkout:function(){
          pushNewsbreakPixel("initiate_checkout")
        },
        sign_up:function(){
          pushNewsbreakPixel("complete_registration")
        },
        
      })
    }) 
</script>
{% endif %}
{% endif %}
